<template>
  <div>
    <div class="title">
      <div>作业列表</div>
    </div>
    <div class="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="name" label="作业名称" width="800" />
        <el-table-column prop="achievement" label="分数" width="200" />
        <el-table-column prop="state" label="是否完成" width="200" />
        <el-table-column prop="check" label="查看" width="140" align="center" />
      </el-table>
      <div class="pagination">
        <el-pagination
          :page-size="14"
          background
          layout="prev, pager, next"
          :total="max"
          @current-change="currentChange"
        />
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import {Job} from "@/interface"
import {ref, onMounted} from "vue"
import {Student} from "../../api"
const tableData = ref()
const max = ref(0)
const currentChange = (val: number) => {
  upDate(val)
}
const upDate = async (page: number = 1) => {
  const res = await Student.getHomeworkByStudentIdPage({studentId: 111, page: page})
  tableData.value = res.data.data.HomeworkArr.map((item: Job) => ({
    name: item.Homework!.name,
    achievement: item.achievement,
    state: item.state == 1 ? "完成" : "未完成",
    check: "查看"
  }))
}
onMounted(async () => {
  const res = await Student.getStudentMax({studentId: 111})
  max.value = res.data.data.dataArr
  upDate()
})
</script>
<style lang="scss" scoped>
.title {
  display: flex;
  justify-content: space-between;
  padding: 50px 50px 0;
}
.table {
  margin-top: 50px;
  padding: 0 50px;
  height: 600px;
  position: relative;
  .pagination {
    position: absolute;
    bottom: -50px;
    right: 20px;
  }
}
</style>
